<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
           <a-col :span="24">
            <a-form-model-item label="商标申请号/注册号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applicationNo">
              <a-input v-model="model.applicationNo" placeholder="请输入商标申请号/注册号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="已覆盖类似群" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">
              <a-input v-model="model.code" placeholder="请输入已覆盖类似群"  ></a-input>
            </a-form-model-item>
          </a-col>
           <a-col :span="24">
            <a-form-model-item label="类似群的价值等级" :labelCol="labelCol" :wrapperCol="wrapperCol" >
               <a-select v-model="model.valueLevel" placeholder="">
                   <a-select-option value="0"  key="类似群的价值等级">
                    待定
                  </a-select-option>
                  <a-select-option :value="item" v-for="item of 3" :key="item">
                    {{`${item}级`}}
                  </a-select-option>
                </a-select>
            </a-form-model-item>
          </a-col>
          
          <a-col :span="24">
            <a-form-model-item label="已申请/核定商品/服务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="goodsService">
             <a-textarea :autosize="true" v-model="model.goodsService" placeholder="请输入已申请/核定商品/服务"  ></a-textarea>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="类似群的价值等级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="valueLevel">
              <a-input-number v-model="model.valueLevel" placeholder="请输入类似群的价值等级" style="width: 100%" />
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="具体增值点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="addedValue">
              <a-input v-model="model.addedValue" placeholder="请输入具体增值点"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="具体使用的商品" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="specificUseGoods">
              <a-textarea :autosize="true" v-model="model.specificUseGoods" placeholder="请输入具体使用的商品"  ></a-textarea>
              </a-form-model-item>
          </a-col>
         <a-col :span="24">
            <a-form-model-item label="具体使用的服务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="specificUseService">
             <a-textarea  v-model="model.specificUseService" placeholder="请输入具体使用的服务"  ></a-textarea>
          </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="是否撤销风险" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isCancelRisk">
              <a-input v-model="model.isCancelRisk" placeholder="请输入是否撤销风险"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="撤销风险等级" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cancelRiskLevel">
              <a-input-number v-model="model.cancelRiskLevel" placeholder="请输入撤销风险等级" style="width: 100%" />
            </a-form-model-item>
          </a-col> -->
       
         
         
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'BrandSimilitudeGroupForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          //  code: [
          //     { required: true, message: '请输入已覆盖类似群!'},
          //  ],
           goodsService: [
              { required: true, message: '请输入已申请/核定商品/服务!'},
           ],
           applicationNo: [
              { required: true, message: '请输入商标申请号/注册号!'},
           ],
        },
        url: {
          add: "/knowledge/brandSimilitudeGroup/add",
          edit: "/knowledge/brandSimilitudeGroup/edit",
          queryById: "/knowledge/brandSimilitudeGroup/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
        delete this.validatorRules.code;
        this.validatorRules = Object.assign({},this.validatorRules)
        
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
        this.validatorRules = Object.assign(this.validatorRules,{ code: [{ required: true, message: '请输入已覆盖类似群!'}]})
        this.validatorRules = Object.assign({},this.validatorRules)
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>